package com.xx;

import lombok.experimental.UtilityClass;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@UtilityClass
public class Util {

    /**
     * 映射标记
     */
    public static final String MAPPING = "[mapping#";

    /**
     * 中括号
     */
    public static final String BRACKET = "]";

    /**
     * 逗号
     */
    public static final String COMMA = ",";

    /**
     * 冒号
     */
    public static final String COLON = ":";

    /**
     * 获得映射规则
     *
     * @param input 内容
     * @return 规则
     */
    public static String fetchMapping(String input) {
        String regex = "\\" + MAPPING + ".*\\]";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(input);
        if (matcher.find()) {
            return matcher.group();
        }
        return null;
    }
}
